﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using PhongMachTu.OConnection;
using PhongMachTu.OModel;

namespace PhongMachTu.OForm
{
    public partial class FormSearchPaInfo : Form
    {
        private ArrayList patients;

        public FormSearchPaInfo()
        {
            InitializeComponent();
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            if (OSession.isLoggedIn())
            {
                lvPatient.Items.Clear();
                patients = DataManipulate.searchPaInfo(txtKeyWord.Text);
                if (patients != null)
                {
                    for (int i = 0; i < patients.Count; i++)
                    {
                        int stt = i + 1;
                        Patient pa = (Patient)patients[i];
                        int id = pa.PatienId;
                        String fullname = pa.Fullname;
                        String visitDate = pa.VisitDate;
                        String symptom = pa.Symptom;
                        String disease = pa.Disease;

                        ListViewItem item = new ListViewItem(stt.ToString());
                        item.SubItems.Add(id.ToString());
                        item.SubItems.Add(fullname);
                        item.SubItems.Add(visitDate);
                        item.SubItems.Add(symptom);
                        item.SubItems.Add(disease);
                        item.Tag = pa;
                        lvPatient.Items.Add(item);
                    }
                }
                else
                {
                    MessageBox.Show("Không tìm thấy bệnh nhân này !", "Thông báo");
                }
            }
            else
            {
                FormManager.searchPaInfoForm.Hide();
                FormManager.loginForm.Show();
                MessageBox.Show("Quá thời gian chờ cho phép, vui lòng đăng nhập lại");
            }
        }

        private void FormSearchPaInfo_FormClosing(object sender, FormClosingEventArgs e)
        {
            e.Cancel = true;
            FormManager.searchPaInfoForm.Hide();
            FormManager.mainForm.Show();
        }
    }
}
